<?php

namespace App;

use App\Http\Services\FileManager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\PrescriptionInfoImgs
 *
 * @property int $id
 * @property int $prescription_info_id 处方信息id
 * @property int $img_id 处方图片
 * @property string|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs whereImgId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs wherePrescriptionInfoId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs whereUpdatedAt($value)
 * @mixin \Eloquent
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Query\Builder|\App\PrescriptionInfoImgs onlyTrashed()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\PrescriptionInfoImgs withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\PrescriptionInfoImgs withoutTrashed()
 * @property string|null $img_url 处方图片
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfoImgs whereImgUrl($value)
 */
class PrescriptionInfoImgs extends Model
{
    //
    use SoftDeletes;

    public static function getPrescriptionInfoImgList($prescription_info_id = 0){
        $data = [];
        $prescriptionInfoImgList = self::wherePrescriptionInfoId($prescription_info_id)->get();
        if(count($prescriptionInfoImgList) > 0){
            foreach ($prescriptionInfoImgList as $prescriptionInfoImg) {
                $imgUrl = FileManager::getImgUrl($prescriptionInfoImg->img_id);
                $item = [
                    'id' => $prescriptionInfoImg->img_id,
                    'img_url' => $imgUrl
                ];

                array_push($data,$item);
            }
        }

        return $data;
    }
}
